package com.yaosheng.thread.threadPool;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created by yaosheng on 2021/7/7.
 * 定时任务线程池
 */
public class ScheduledPool {

    public static void main(String[] args) {

        ScheduledExecutorService executor = Executors.newScheduledThreadPool (4);
        executor.scheduleAtFixedRate ( () -> {
            try{
                TimeUnit.SECONDS.sleep (1);
            } catch (InterruptedException e) {
                e.printStackTrace ();
            }
            System.out.println (Thread.currentThread ().getName ());
        },0,500,TimeUnit.MILLISECONDS);
        //initialDelay:初始线程启动时间间隔，period:每个线程启动时间间隔，TimeUnit.MILLISECONDS:时间格式（MILLISECONDS:毫秒）
    }
}
